use "data/working/data_scpc.dta", clear

*------------------------------------------------------------------------------*
* Data Clean *
*------------------------------------------------------------------------------*


*clean the date format
gen date_clock = clock( tsstart , "20YMDhms")
gen date = dofc( date_clock )
format date_clock %tc
format date %td

*merge m:1 date using "data/coinmarketcap_bitcoin2.dta", nogenerate force
*drop if missing(prim_key)

*------------------------------------------------------------------------------*
* Variables *
*------------------------------------------------------------------------------*

label define exp 1 "Decrease a lot" 2 "Decrease some" 3 "Stay about the same" 4 "Increase some" 5 "Increase a lot"
label values bitcoin_expectation_nextweek exp
label values bitcoin_expectation_nextmonth exp
label values bitcoin_expectation_nextyear exp

*weekly expectation
gen exp_inc_week = (bitcoin_expectation_nextweek == 4) + (bitcoin_expectation_nextweek == 5) if bitcoin_expectation_nextweek != .
gen exp_dec_week = (bitcoin_expectation_nextweek == 1) + (bitcoin_expectation_nextweek == 2) if bitcoin_expectation_nextweek != .
gen exp_same_week = (bitcoin_expectation_nextweek == 3) if bitcoin_expectation_nextweek != .

label variable exp_inc_week "Week Increase"
label variable exp_dec_week "Week Decrease"
label variable exp_same_week "Week Same"

*monthly expectation
gen exp_inc_month = (bitcoin_expectation_nextmonth == 4) + (bitcoin_expectation_nextmonth == 5) if bitcoin_expectation_nextmonth != .
gen exp_dec_month = (bitcoin_expectation_nextmonth == 1) + (bitcoin_expectation_nextmonth == 2) if bitcoin_expectation_nextmonth != .
gen exp_same_month = (bitcoin_expectation_nextmonth == 3) if bitcoin_expectation_nextmonth != .

label variable exp_inc_month "Month Increase"
label variable exp_dec_month "Month Decrease"
label variable exp_same_month "Month Same"

*yearly expectation
gen exp_inc_year = (bitcoin_expectation_nextyear == 4) + (bitcoin_expectation_nextyear == 5) if bitcoin_expectation_nextyear != .
gen exp_dec_year = (bitcoin_expectation_nextyear == 1) + (bitcoin_expectation_nextyear == 2) if bitcoin_expectation_nextyear != .
gen exp_same_year = (bitcoin_expectation_nextyear == 3) if bitcoin_expectation_nextyear != .

label variable exp_inc_year "Year Increase"
label variable exp_dec_year "Year Decrease"
label variable exp_same_year "Year Same"

*gender
label define genderlabel 1 "Gender: Male" 2 "Gender: Female"
label values gender genderlabel
gen male = gender==1

* Age
gen age = scpc_year - birthyear

* Age dummy: <=45 & >45
gen agenewdummy = (age <= 45) if !missing(age)
label define agenewlabel 0 "Age above 30" 1 "Age below 30"
label values agenewdummy agenewlabel
label variable agenewdummy "Age below 30"

*Income

recode income_band (1 = 2500) (2 = 6250) (3 = 8750) (4 = 11250) (5 = 13750) (6 = 17500) ///
(7 = 22500) (8 = 27500) (9 = 32500) (10 = 37500) (11 = 45000) (12 = 55000) (13 = 67500) ///
(14 = 82500) (15 = 112500) (16 = 162500) (17 = 350000) (18 = 750000) ///
if scpc_year != 2018, gen(income_new)

recode income_band (1 = 2500) (2 = 6250) (3 = 8750) (4 = 11250) (5 = 13750) (6 = 17500) ///
(7 = 22500) (8 = 27500) (9 = 32500) (10 = 37500) (11 = 45000) (12 = 55000) (13 = 67500) ///
(14 = 82500) (15 = 125000) (16 = 200000) if scpc_year == 2018, gen(income_new_2018) ///

replace income_new = income_new_2018 if scpc_year == 2018

*Asset dummy: <=20k & >20k (median)
gen assetdummy = (asset <= 20000) if !missing(asset)
label define assetlabel 0 "Above 20K" 1 "Below 20K"
label values assetdummy assetlabel
label variable assetdummy "Asset below 20K"

*Income dummy: <=100k & >100k
gen incomenewdummy = (income_new <= 100000) if !missing(income_band)
label define incomenewlabel 0 "Above 100K" 1 "Below 100K"
label values incomenewdummy incomenewlabel
label variable incomenewdummy "Income below 100K"

*Education

recode highesteducation (1 = 0) (2 = 0) (3 = 0) (4 = 0) (5 = 0) (6 = 0) ///
(7 = 0) (8 = 0) (9 = 0) (10 = 1) (11 = 2) (12 = 2) (13 = 2) ///
(14 = 3) (15 = 3) (16 = 3), gen(edu_new)

label variable edu_new "Education"

label define edu_newlabel 0 "Education: High school and below" 1 "Education: Some college" ///
2 "Education: Bachelors degree" 3 "Education: Graduate degree"

label values edu_new edu_newlabel

gen loweducation = edu_new==0 | edu_new==1


* net worth
gen asset_k = asset/1000
label variable asset_k "Net worth (k dollors)"

* bitcoin dollar
gen bitcoin_dollar_m = bitcoin_dollar/1000000
label variable bitcoin_dollar_m "How much Bitcoin (m dollars)"


*------------------------------------------------------------------------------*
* Save *
*------------------------------------------------------------------------------*

save "data/working/working_scpc.dta", replace

